package com.example.synchronizeddemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn_sync_test;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
    }

    private void initView() {
        btn_sync_test = findViewById(R.id.btn_sync_test);
        btn_sync_test.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Person xiaoming = new Person("小明");
        switch (v.getId()){
            case R.id.btn_sync_test:
                Thread thread1 = new Thread(){
                    private String TAG = "thread1";
                    @Override
                    public void run() {
                        super.run();
                        Log.e(TAG, "run: " + "开始执行" + "/ time:" +System.currentTimeMillis() );
                        xiaoming.speaksynchronized();
                    }
                };
                Thread thread2 = new Thread(){
                    private String TAG = "thread2";
                    @Override
                    public void run() {
                        super.run();
                        Log.e(TAG, "run: " + "开始执行" + "/ time:" +System.currentTimeMillis() );
                        xiaoming.speaksynchronized();
                    }
                };
                thread1.start();
                thread2.start();
                break;
            default:
                break;
        }
    }
}